package hxy.bytecode.datastruct.list;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;

/**
 * @author eric
 * @program bytecode
 * @description
 * @date 2022/1/10
 */
public class ArrayListIteratorTest {
    public static void main(String[] args) {
        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(1);
        arrayList.add(2);
        arrayList.add(3);
        arrayList.add(4);

        Iterator<Integer> iterator = arrayList.iterator();
        while (iterator.hasNext()) {
            Integer next = iterator.next();
            if (next == 2) {
                iterator.remove();
            }
        }

        System.out.println(Arrays.toString(arrayList.toArray()));

    }
}
